package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.FamilyMemberElderDto;
import com.zzyl.nursing.dto.QueryDeviceDataByDay;
import com.zzyl.nursing.dto.QueryDevicePropertyStatusDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/member/user")
@Api(tags = "用户管理")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        log.info("用户登录信息：{}", userLoginRequestDto);
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return AjaxResult.success(loginVo);
    }
    @PostMapping("/add")
    @ApiOperation("添加家属绑定老人信息")
    public AjaxResult add(@RequestBody FamilyMemberElderDto dto) {
        log.info("添加家属绑定老人信息：{}", dto);
        familyMemberElderService.bindingElder(dto);
        return AjaxResult.success();
    }
    @GetMapping("/my")
    @ApiOperation("查询当前登录用户的家属信息")
    public AjaxResult my() {
        log.info("查询当前登录用户的家属信息");
        List<FimalyVo> fimalyVos =familyMemberElderService.my();
        return AjaxResult.success(fimalyVos);
    }

    /*@GetMapping("/list-by-page")
    @ApiOperation("分页查询当前登录用户的家属信息")
    public TableDataInfo<List<ElderFamilyPageVo>> listByPage(@RequestParam(required = false) Integer pageNum,
                                                             @RequestParam(required = false) Integer pageSize) {
        log.info("分页查询当前登录用户的家属信息{},{}" , pageNum, pageSize);
        startPage();
        List<ElderFamilyPageVo> fimalyVos =familyMemberElderService.listByPage();
        return getDataTable(fimalyVos);
    }*/
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询当前登录用户的家属信息")
    public AjaxResult listByPage(@RequestParam(required = false) Integer pageNum,
                                                             @RequestParam(required = false) Integer pageSize) {
        log.info("分页查询当前登录用户的家属信息{},{}" , pageNum, pageSize);
        startPage();
        List<ElderFamilyPageVo> list =familyMemberElderService.listByPage();
        return success(list);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询设备属性状态")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusDto dto) {
        log.info("查询设备属性状态：{}", dto);
        QueryDevicePropertyStatusObject list = familyMemberService.queryDevicePropertyStatus(dto);
        return AjaxResult.success(list);
    }

    /**
     * 按天查询设备数据列表
     * @param
     *
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天查询设备数据列表")
    public AjaxResult queryDeviceDataListByDay(String functionId,Long startTime, Long endTime,String iotId) {
        log.info("按天查询设备数据列表参数为{},{},{},{}",functionId,startTime,endTime,iotId);
        List<Map<String, Object>> list = familyMemberService.queryDeviceDataListByDay(functionId,startTime,endTime,iotId);
        return AjaxResult.success(list);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周查询设备数据列表")
    public AjaxResult queryDeviceDataListByWeek(String functionId,Long startTime, Long endTime,String iotId) {
        log.info("查询设备数据列表的参数为:{},{},{},{}", functionId, startTime, endTime, iotId);
        List<Map<String, Object>> list = familyMemberService.queryDeviceDataListByWeek(functionId, startTime, endTime, iotId);
        return AjaxResult.success(list);
    }

    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(Long id) {
        log.info("删除参数为:{}", id);
        familyMemberElderService.removeById(id);
        return AjaxResult.success();
    }




}
